﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xushre.WeiBoSDK {

    public partial class OClient2 {

        /// <summary>
        /// 获取当前登录用户的隐私设置
        /// </summary>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountGetPrivacy() {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            try {
                response = Get(API.OClient2.Account.GET_PRIVACY, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }

        /// <summary>
        /// 获取所有的学校列表
        /// </summary>
        /// <remarks>
        /// 参数keyword与capital二者必选其一，且只能选其一
        /// 按首字母capital查询时，必须提供province参数
        /// </remarks>
        /// <param name="province">省份范围，省份ID。</param>
        /// <param name="city">城市范围，城市ID。</param>
        /// <param name="area">区域范围，区ID。</param>
        /// <param name="type">学校类型，1：大学、2：高中、3：中专技校、4：初中、5：小学，默认为1。</param>
        /// <param name="capital">学校首字母，默认为A。</param>
        /// <param name="keyword">学校名称关键字。</param>
        /// <param name="count">返回的记录条数，默认为10。</param>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountProfileSchoolList(int province = 0, int city = 0, int area = 0, int type = 1, string capital = "A", string keyword = null, int count = 10) {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            if (!string.IsNullOrEmpty(capital)) {
                if (province <= 0) {
                    return "{\"error\":\"When you search by first letter capital, you must provide the province parameter.\",\"error_code\":9005}";
                }
                data.Add("capital", capital);
                data.Add("province", province);
            } else if (!String.IsNullOrEmpty(keyword)) {
                data.Add("keyword", keyword);
            } else {
                return "{\"error\":\"Parameter keyword and capital will be one of the two, and only one of.\",\"error_code\":9004}";
            }

            if (province > 0) {
                data.Add("province", province);
            }
            if (city > 0) {
                data.Add("city", city);
            }
            if (area > 0) {
                data.Add("area", area);
            }
            data.Add("type", type);
            data.Add("count", count);

            try {
                response = Get(API.OClient2.Account.Profile.SCHOOL_LIST, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }

        /// <summary>
        /// 获取当前登录用户的API访问频率限制情况
        /// </summary>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountRateLimitStatus() {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            try {
                response = Get(API.OClient2.Account.RATE_LIMIT_STATUS, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }

        /// <summary>
        /// 获取用户的联系邮箱
        /// </summary>
        /// <remarks>
        /// 本接口获取到的是用户的联系邮箱，而非安全邮箱
        /// 需要用户先完成Scope授权
        /// </remarks>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountProfileEmail() {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            try {
                response = Get(API.OClient2.Account.Profile.EMAIL, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }

        /// <summary>
        /// OAuth授权之后，获取授权用户的UID
        /// </summary>
        /// <remarks>
        /// 1. 用户OAuth授权之后获取用户UID，作用相当于旧版接口的（account/verify_credentials）
        /// 2. 此接口不计入访问频次中
        /// </remarks>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountGetUid() {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            try {
                response = Get(API.OClient2.Account.GET_UID, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }

        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns>JSON 格式的客串</returns>
        /// <exception cref="WeiboException"></exception>
        public string AccountEndSession() {
            string response = string.Empty;
            Dictionary<string, object> data = new Dictionary<string, object>();

            try {
                response = Get(API.OClient2.Account.END_SESSION, data);
            } catch (WeiboException e) {
                throw e;
            }

            return response;
        }
    }
}
